package com.guigui.erp.controller;

import com.guigu.erp.dto.SysMenuDto;
import com.guigu.erp.service.SystemMenusService;
import com.guigu.erp.service.SystemUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Lenovo
 */
@CrossOrigin
@Controller
@RequestMapping("/System/Menus")
public class SystemMenusController {
    @Autowired
    private SystemMenusService systemMenusService;

    //查询当前用户所有权限
    @RequestMapping("getMenus/{uid}")
    @ResponseBody
    public List<SysMenuDto> getMenus(@PathVariable int uid){
        List<SysMenuDto> menus = systemMenusService.getMenus(uid);
        for(int i=0;i<menus.size();i++){
            menus.get(i).setSubmenus(systemMenusService.getSubmenus(menus.get(i).getParentId()));
        }
        return menus;
    }
}
